package com.leeyu.rabbitmq.publisher;

import com.leeyu.rabbitmq.config.HeaderConfig;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class HeaderPublisherTest {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void publish(){
        String message = "Hello Header Exchange!";
        rabbitTemplate.convertAndSend(HeaderConfig.HEADER_EXCHANGE, "", message, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setHeader("name","abc");
                message.getMessageProperties().setHeader("value","123");
                return message;
            }
        });
    }
}
